package com.aijk.web.admin.controller.h5;

import com.aijk.ehm.api.EhmBannerApi;
import com.aijk.ehm.model.EhmBanner;
import com.aijk.web.admin.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "h5/banner")
public class BannerH5Controller extends BaseController {
    @Autowired
    private EhmBannerApi bannerApi;


    @RequestMapping(value = "browse/{id}")
    public Object browse(@PathVariable("id") Long id, HttpServletRequest request, Model model) {
        EhmBanner basBanner = bannerApi.findOne(id);
        //广告信息未找到
        if(basBanner == null){
            model.addAttribute("errorMessage","该信息已被删除或已注销");
            return "/error/errorMessage";
        }
        //图文方式
        if(basBanner.getHrefType() == 1){
            model.addAttribute("object",basBanner);
            return "/h5/banner/browse";
        }
        //外链方式或者内链
        return "redirect:"+basBanner.getHrefUrl();
    }


}

